﻿Imports Publics
Imports System.Windows.Forms

Public Class FrmDialogDMQ
    Private _vPermission As DM_QUYEN
    Private _vDataSource As Collections.Generic.List(Of DM_QUYEN)
    Public Property vPermission() As DM_QUYEN
        Get
            Return _vPermission
        End Get
        Set(ByVal value As DM_QUYEN)
            _vPermission = value
        End Set
    End Property

    Public Property vDataSource() As Collections.Generic.List(Of DM_QUYEN)
        Get
            Return _vDataSource
        End Get
        Set(ByVal value As Collections.Generic.List(Of DM_QUYEN))
            _vDataSource = value
        End Set
    End Property


    ''' <summary>
    ''' Hiển thị thông tin phím tắt trên caption của form
    ''' @NhiLV
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub GetCaptionForm()
        Dim strChon As String = String.Empty
        Dim strThoat As String = GetStrKey(kThoat)
        If btnChapNhan.Visible = True And btnChapNhan.Enabled = True Then
            strChon = GetStrKey(kChon)
        End If

        'If btnTroGiup.Visibility = DevExpress.XtraBars.BarItemVisibility.Always And btnTroGiup.Enabled = True Then
        '    strTroGiup = GetStrKey(kTroGiup)
        'End If
        Me.Text = Me.Text + strChon + strThoat 'strTroGiup + 
    End Sub

    Private Sub FrmDialogDMQ_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            vDataSource = (From ds In dbTV.DM_Quyens _
                           Where ds.InUsed _
                           Order By ds.ThuTu, ds.TenQuyen _
                           Select ds).ToList()
            Me.vTreeDMQuyen.DataSource = vDataSource
            Me.vTreeDMQuyen.Refresh()
            Me.vTreeDMQuyen.CollapseAll()
            'GetCaptionForm()
        Catch ex As Exception
            MsgErr(ex.Message)
        End Try

    End Sub


    Private Sub btnHuyBo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHuyBo.Click
        Me.Close()
    End Sub

    Private Sub btnChapNhan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnChapNhan.Click
        If Me.vTreeDMQuyen.FocusedNode IsNot Nothing Then
            Try
                Me.vPermission = (From ds In vDataSource _
                                  Where ds.ID.Equals(CStr(Me.vTreeDMQuyen.FocusedNode.GetValue(vTreeColumnID))) _
                                  Select ds).FirstOrDefault()
                Me.Close()
            Catch ex As Exception
                MsgErr(ex.Message)
            End Try
        End If
    End Sub

    Private Sub vTreeDMQuyen_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles vTreeDMQuyen.KeyDown
        If Me.vTreeDMQuyen.FocusedNode IsNot Nothing Then
            Select Case e.KeyCode
                Case Keys.Right
                    Me.vTreeDMQuyen.FocusedNode.Expanded = True
                Case Keys.Left
                    Me.vTreeDMQuyen.FocusedNode.Expanded = False
                Case Keys.Enter
                    Try
                        Me.vPermission = (From ds In vDataSource _
                                          Where ds.ID.Equals(CStr(Me.vTreeDMQuyen.FocusedNode.GetValue(vTreeColumnID))) _
                                          Select ds).FirstOrDefault()
                        Me.Close()
                    Catch ex As Exception
                        MsgErr(ex.Message)
                    End Try
            End Select
        End If
    End Sub

    Private Sub FrmDialogDMQ_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
        'Chấp nhận
        If (e.Modifiers = GetKeyModifide(pIdChon) And _
                                e.KeyCode = GetKeyCode2(pIdChon)) Or _
                                (e.KeyCode = GetKeyCode(pIdChon)) Then

            If Me.btnChapNhan.Enabled = True And Me.btnChapNhan.Visible = True Then
                btnChapNhan_Click(Nothing, Nothing)
            End If

        End If
        'Huỷ bỏ (thoát)
        If (e.Modifiers = GetKeyModifide(pIdThoat) And _
                e.KeyCode = GetKeyCode2(pIdThoat)) Or _
                (e.KeyCode = GetKeyCode(pIdThoat)) Then
            Me.Close()
        End If
    End Sub
End Class